﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using nplJobsCommon.Common;
using nplJobsDAL;
using nplJobs.DB;
using System.Data;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Web.Services;

using nplJobsCommon.JobSeeker;
using Elmah;
public partial class Employeer_SearchCV : BasePage // System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HttpContext.Current.Session["user"] != null && HttpContext.Current.Session["user"].Equals(General.Users.JobSeeker.ToString()))
        {
            Response.Redirect("../JobSeeker/EditProfile.aspx");
            return;
        }
        base.ReloadUserInfoSession();

        if (!Page.IsPostBack)
        {
            HttpContext.Current.Session["SearchData"] = null;
            Page.Title = "Search cv";

        }
    }

    static DataSet AddPagerTableToDS(DataSet ds, int pageIndex, int pageSize)
    {
        DataSet dsNew = new DataSet();
        if (ds != null)
        {
            dsNew = ds.Copy();
            if (!dsNew.Tables.Contains("GridData"))
            {
                dsNew.Tables[0].TableName = "GridData";
            }
            if (!ds.Tables.Contains("PagerData"))
            {
                DataTable pager = new DataTable("PagerData");
                DataColumn dc = new DataColumn("RecordCount");
                pager.Columns.Add(dc);
                DataRow row = pager.NewRow();
                row["RecordCount"] = ds.Tables[0].Rows.Count;
                pager.Rows.Add(row);
                dsNew.Tables.Add(pager);
            }


            int endIndex = pageSize;

            if (pageIndex > 1)
            {
                endIndex = pageIndex * pageSize;
                pageIndex = pageSize * (pageIndex - 1);
            }
            else
                pageIndex = 0;

            if (endIndex > ds.Tables[0].Rows.Count)
            {
                endIndex = ds.Tables[0].Rows.Count;
            }

            DataTable dt = null;
            if (dsNew.Tables["GridData"].Rows.Count <= 1)
            {
                dt = dsNew.Tables["GridData"];
            }
            else
                dt = dsNew.Tables["GridData"].AsEnumerable().Where((r, index) => (index >= (pageIndex)) && (index < endIndex)).CopyToDataTable();

            dsNew.Tables.Remove("GridData");
            dsNew.Tables.Add(dt);
            dsNew.Tables[1].TableName = "GridData";

        }
        return dsNew;
    }

    #region database queries

    public static DataSet GetAllDataTableFromSearchButton(int pageSize, int pageIndex, string updateTime, string xp, string[] title, string[] location, string[] category, string[] employmentType, string[] qualification, string[] skills)
    {
        DataSet ds = GetDataTableFromDatabase(0, -1);

        if (ds.Tables[0] != null)
        {
            DataTable dt = new DataTable();

            #region category

            DataTable categoryDT = new DataTable();
            if (category.Length > 0)
            {
                categoryDT = GetDataTableJobSeekerByCategory(category, ds);
                ds.Tables.RemoveAt(0);
                ds.Tables.Add(categoryDT);
            }

            #endregion

            #region skills

            DataTable skDt = new DataTable();
            if (skills != null && skills.Length > 0)
            {
                skDt = GetDataTableFromDatabaseBySkill(skills, ds);
                ds.Tables.RemoveAt(0);
                ds.Tables.Add(skDt);
            }

            #endregion

            #region Title
            DataTable titleDt = new DataTable();
            if (title != null && title.Length > 0)
            {
                titleDt = GetDataTableFromDatabaseByTitle(title, ds);
                ds.Tables.RemoveAt(0);
                ds.Tables.Add(titleDt);
            }
            #endregion

            #region places
            DataTable placesDt = new DataTable();
            if (location != null && location.Length > 0)
            {
                placesDt = GetDataTableJobseekerbyCity(location, ds);
                ds.Tables.RemoveAt(0);
                ds.Tables.Add(placesDt);
                // dt.Merge(placesDt);
            }
            #endregion

            #region Qualification
            DataTable qualificationDt = new DataTable();
            if (qualification != null && qualification.Length > 0)
            {
                qualificationDt = GetDataTableJobseekerbyQualification(qualification, ds);
                ds.Tables.RemoveAt(0);
                ds.Tables.Add(qualificationDt);
                // dt.Merge(qualificationDt);
            }
            #endregion

            #region Jobtype

            employmentType = employmentType.Where(x => x != "Any").ToArray();
            if (employmentType != null && employmentType.Length > 0)
            {
                employmentType = employmentType.TakeWhile(n => n.Length > 0).ToArray();
                DataTable empTypeDt = new DataTable();
                empTypeDt = GetDataTableFromDatabaseByEmploymentType(employmentType, ds);
                ds.Tables.RemoveAt(0);
                ds.Tables.Add(empTypeDt);
                // dt.Merge(empTypeDt);
            }

            #endregion

            #region experience

            if (xp != null && !("Any").Equals(xp))
            {
                DataTable experienceDt = new DataTable();
                experienceDt = GetDataTableByExperienceDropDown(xp, ds);
                ds.Tables.RemoveAt(0);
                ds.Tables.Add(experienceDt);
                // dt.Merge(experienceDt);
            }

            #endregion

            #region cv update

            if (updateTime != null && !("Any Time".Equals(updateTime)))
            {
                DataTable cvUpdateDt = new DataTable();
                cvUpdateDt = GetDatatbaleByCVUpdateDropDown(updateTime, ds);
                ds.Tables.RemoveAt(0);
                ds.Tables.Add(cvUpdateDt);
                //dt.Merge(cvUpdateDt);
            }

            #endregion


            if (ds.Tables[0].Rows.Count > 0)
            {
                dt = ds.Tables[0].AsEnumerable().Distinct(DataRowComparer.Default).CopyToDataTable();
                ds.Tables.Remove(ds.Tables[0]);
                ds.Tables.Add(dt);
            }

            ///For paging requestit will be populated from getData and then GetAllDataTableFromDatabase
            HttpContext.Current.Session["SearchData"] = ds;

            ///For every new search ,page index is started from 1
            return AddPagerTableToDS(ds, pageIndex, pageSize);
        }

        return ds;
    }

    public static DataTable GetDataTableFromDatabaseByTitle(string[] titles, DataSet ds)
    {
        List<ProfessionalInfo> listProfessionalInfo;
        DataTable titleDT = new DataTable();
        DataTable tmp = null;
        nplJobsBLL.ProcessJobSeeker.ProcessSelectProfessionalInfo ps = new nplJobsBLL.ProcessJobSeeker.ProcessSelectProfessionalInfo();

        foreach (string tl in titles)
        {
            if (!string.Empty.Equals(tl))
            {
                foreach (DataRow r in ds.Tables[0].Rows)
                {
                    ps.JobseekerID = (Guid)r["jobseekerid"];
                    ps.ProfessionalInfoID = -1;
                    ps.invoke();
                    listProfessionalInfo = ps.ProfessionalInfo;
                    if (listProfessionalInfo.Where(i => i.Title.ToUpper() == tl.ToUpper()).Count() != 0)
                    {
                        tmp = ds.Tables[0].AsEnumerable().Where(i => (i.Field<Guid>("jobseekerid") != null && i.Field<Guid>("jobseekerid") == ps.JobseekerID)).CopyToDataTable();
                        titleDT.Merge(tmp);
                    }
                }
            }
        }

        return titleDT;
    }

    public static DataTable GetDataTableByExperienceDropDown(string experice, DataSet ds)
    {
        DataTable experienceDt = new DataTable();

        if (experice.StartsWith("<"))
        {
            experice = experice.Replace('<', '-');
        }
        int exp = 0;
        int.TryParse(experice, out exp);
        exp = exp * 12;

        if (exp > 0)
        {
            if (ds.Tables[0].AsEnumerable().Where(i => i.Field<int>("expCount") >= exp).Count() != 0)
                experienceDt = ds.Tables[0].AsEnumerable().Where(i => i.Field<int>("expCount") >= exp).CopyToDataTable();
        }
        else if (exp < 0)
        {
            if (ds.Tables[0].AsEnumerable().Where(i => i.Field<int>("expCount") <= exp * (-1)).Count() != 0)
                experienceDt = ds.Tables[0].AsEnumerable().Where(i => i.Field<int>("expCount") <= exp * (-1)).CopyToDataTable();
        }

        return experienceDt;
    }

    public static DataTable GetDatatbaleByCVUpdateDropDown(string updateTime, DataSet ds)
    {
        DateTime date = DateTime.Today;
        DateTime td = new DateTime();
        DataTable dt = new DataTable();

        if (updateTime == "Last 6 Month")
        {
            td = date.AddMonths(-6);
        }
        else if (updateTime == "Last Month")
        {
            td = date.AddMonths(-1);
        }
        else if (updateTime == "Last Week")
        {
            td = date.AddDays(-7);
        }

        if (ds.Tables[0].AsEnumerable().Where(i => i.Field<DateTime>("ModifiedOn") >= td).Count() != 0)
        {
            dt = ds.Tables[0].AsEnumerable().Where(i => i.Field<DateTime>("ModifiedOn") >= td).CopyToDataTable();
        }

        return dt;
    }

    public static DataTable GetDataTableFromDatabaseBySkill(string[] skills, DataSet ds)
    {
        DataTable skDt = new DataTable();
        DataTable tmp = new DataTable();
        foreach (string ski in skills)
        {
            if (!string.Empty.Equals(ski))
            {
                if (ds.Tables[0].AsEnumerable().Where(i => (i.Field<string>("SkillOne") != null && i.Field<string>("SkillOne").ToUpper() == ski) ||
                                                           (i.Field<string>("SkillTwo") != null && i.Field<string>("SkillTwo").ToUpper() == ski) ||
                                                           (i.Field<string>("SkillThree") != null && i.Field<string>("SkillThree").ToUpper() == ski) ||
                                                           (i.Field<string>("SkillFour") != null && i.Field<string>("SkillFour").ToUpper() == ski) ||
                                                           (i.Field<String>("skills") != null && i.Field<String>("skills").ToUpper().Contains(ski))
                                                           ).Count() != 0)
                    tmp = ds.Tables[0].AsEnumerable().Where(i => (i.Field<string>("SkillOne") != null && i.Field<string>("SkillOne").ToUpper() == ski) ||
                                                           (i.Field<string>("SkillTwo") != null && i.Field<string>("SkillTwo").ToUpper() == ski) ||
                                                           (i.Field<string>("SkillThree") != null && i.Field<string>("SkillThree").ToUpper() == ski) ||
                                                           (i.Field<string>("SkillFour") != null && i.Field<string>("SkillFour").ToUpper() == ski) ||
                                                           (i.Field<String>("skills") != null && i.Field<String>("skills").ToUpper().Contains(ski) && i.Field<String>("skills").Length == ski.Length)
                                                           ).CopyToDataTable();
                skDt.Merge(tmp);
            }
        }
        return skDt;
    }

    public static DataTable GetDataTableJobseekerbyCity(string[] location, DataSet ds)
    {
        DataTable tmp = new DataTable();
        DataTable places = new DataTable();
        foreach (string loc in location)
        {
            if (ds.Tables[0].AsEnumerable().Where(i => (i.Field<string>("City") == loc) || (i.Field<string>("country") == loc)).Count() != 0)
            {
                tmp = ds.Tables[0].AsEnumerable().Where(i => (i.Field<string>("City") == loc) || (i.Field<string>("country") == loc)).CopyToDataTable();
                places.Merge(tmp);
            }
        }

        return places;
    }

    public static DataTable GetDataTableJobseekerbyQualification(string[] qualification, DataSet ds)
    {
        DataTable tmp = new DataTable();
        DataTable qualificationDT = new DataTable();

        foreach (string qual in qualification)
        {
            if (ds.Tables[0].AsEnumerable().Where(i => (GetQualificationByJobseeker(i.Field<Guid>("Jobseekerid")).Contains(qual))).Count() != 0)
            {
                tmp = ds.Tables[0].AsEnumerable().Where(i => (GetQualificationByJobseeker(i.Field<Guid>("Jobseekerid")).Contains(qual))).CopyToDataTable();
                qualificationDT.Merge(tmp);
            }

            if (ds.Tables[0].AsEnumerable().Where(i => i.Field<string>("Qualifications") != null).Where(i => (i.Field<string>("Qualifications").ToUpper().Contains(qual))).Count() != 0)
            {
                tmp = ds.Tables[0].AsEnumerable().Where(i => i.Field<string>("Qualifications") != null).Where(i => (i.Field<string>("Qualifications").ToUpper().Contains(qual))).CopyToDataTable();
                qualificationDT.Merge(tmp);
            }

        }

        return qualificationDT;
    }

    public static List<string> GetQualificationByJobseeker(Guid id)
    {
        nplJobsBLL.ProcessJobSeeker.ProcessSelectEducationalInfo educationalInfo = new nplJobsBLL.ProcessJobSeeker.ProcessSelectEducationalInfo();
        educationalInfo.EducationalInfoID = -1;
        educationalInfo.JobseekerID = id;
        educationalInfo.invoke();
        List<EducationInfo> eInfo = educationalInfo.EducationalInfo;
        List<string> degrees = eInfo.Select(i => i.Degree.ToUpper()).ToList();
        if (degrees.Count == 0)
        {
            degrees.Add("");
        }
        return degrees;
    }

    public static DataSet GetDataTableFromDatabase(int startIndex, int pageSize)
    {
        nplJobsDAL.Select.SelectJobSeekerSearchCV jcv = new nplJobsDAL.Select.SelectJobSeekerSearchCV();
        DataSet ds = jcv.GetJobSeekerForSearchCV(startIndex, pageSize);
        return ds;
    }

    public static DataTable GetDataTableJobSeekerByCategory(string[] search, DataSet jobSeeker)
    {
        DataTable jobSeekerTbl = new DataTable();
        nplJobsDAL.Select.SelectCategoryForJobSeekerSearch catJs = new nplJobsDAL.Select.SelectCategoryForJobSeekerSearch();
        if (catJs.GetCategoryWithJobSeeker().Tables[0].AsEnumerable().Where(p => search.Contains(p.Field<string>("caterogy"))).Count() != 0)
        {
            DataTable CategoriesDb = catJs.GetCategoryWithJobSeeker().Tables[0].AsEnumerable().Where(p => search.Contains(p.Field<string>("caterogy"))).CopyToDataTable();
            List<Guid> jobSeekerIDList = CategoriesDb.AsEnumerable().Select(p => p.Field<Guid>("JobseekerID")).ToList();

            if (jobSeekerIDList.Count > 0)
            {
                jobSeekerTbl = jobSeeker.Tables[0].AsEnumerable().Where(i => jobSeekerIDList.Contains(i.Field<Guid>("JobseekerID"))).CopyToDataTable();
            }
        }

        return jobSeekerTbl;
    }

    public static DataTable GetDataTableFromDatabaseByEmploymentType(string[] employmentType, DataSet ds)
    {
        DataTable employmentTypeDT = new DataTable();
        nplJobsDAL.Select.SelectJobTypeForJobSeekerSearch catJype = new nplJobsDAL.Select.SelectJobTypeForJobSeekerSearch();
        if (catJype.GetJobSeekerByJobType().Tables[0].AsEnumerable().Where(p => employmentType.Contains(p.Field<string>("Type"))).Count() != 0)
        {
            DataTable CategoriesDb = catJype.GetJobSeekerByJobType().Tables[0].AsEnumerable().Where(p => employmentType.Contains(p.Field<string>("Type"))).CopyToDataTable();
            List<Guid> jobSeekerIDList = CategoriesDb.AsEnumerable().Select(p => p.Field<Guid>("JobseekerID")).ToList();


            if (jobSeekerIDList.Count > 0)
            {
                employmentTypeDT = ds.Tables[0].AsEnumerable().Where(i => jobSeekerIDList.Contains(i.Field<Guid>("JobseekerID"))).CopyToDataTable();
            }
        }
        return employmentTypeDT;
    }

    #endregion

    #region Webmethods

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string getByTitle(string search, string pageSize, string updateTime, string experience, string jobTitle, string location, string category, string employmentType, string qualification, string skills)
    {
        string str = string.Empty;
        try
        {

            int pSize = Convert.ToInt32(pageSize);

            string[] title = jobTitle.Split('$');
            string[] locationJ = location.Split('$');
            string[] categoryJ = category.Split('$');
            string[] employmentTypeJ = employmentType.Split('$');
            string[] qualificationJ = qualification.Split('$');
            string[] skillsJ = skills.Trim().Split('$');

            qualificationJ = qualificationJ.TakeWhile(n => n.Length > 0).ToArray();
            employmentTypeJ = employmentTypeJ.TakeWhile(n => n.Length > 0).ToArray();
            categoryJ = categoryJ.TakeWhile(n => n.Length > 0).ToArray();
            locationJ = locationJ.TakeWhile(n => n.Length > 0).ToArray();
            skillsJ = skillsJ.TakeWhile(n => n.Length > 0).ToArray();

            title = title.TakeWhile(n => n.Length > 0).ToArray();
            title[title.Length - 1] = search;///last index gets incomplete text from textbox

            DataSet ds = GetAllDataTableFromSearchButton(pSize, 0, updateTime, experience, title, locationJ, categoryJ, employmentTypeJ, qualificationJ, skillsJ);
            if (ds == null)
                str = "";
            else
                str = ds.GetXml();

        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

        return str;
    }

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string getData(string pageSize, string pageIndex, string categoryText, string updateTime, string experience, string jobTitle, string location, string employmentType, string qualification, string skills)
    {
        string str = string.Empty;
        try
        {
            int pSize = 0;
            if (!string.IsNullOrEmpty(pageSize))
                pSize = Convert.ToInt32(pageSize);
            int pIndex = 0;
            if (!string.IsNullOrEmpty(pageIndex))
                pIndex = Convert.ToInt32(pageIndex);


            string[] title = jobTitle.Split('$');
            string[] locationJ = location.Split('$');
            string[] categoryJ = categoryText.Split('$');
            string[] employmentTypeJ = employmentType.Split('$');
            string[] qualificationJ = qualification.Split('$');
            string[] skillsJ = skills.Trim().Split('$');

            qualificationJ = qualificationJ.TakeWhile(n => n.Length > 0).ToArray();
            employmentTypeJ = employmentTypeJ.TakeWhile(n => n.Length > 0).ToArray();
            categoryJ = categoryJ.TakeWhile(n => n.Length > 0).ToArray();
            locationJ = locationJ.TakeWhile(n => n.Length > 0).ToArray();
            title = title.TakeWhile(n => n.Length > 0).ToArray();
            skillsJ = skillsJ.TakeWhile(n => n.Length > 0).ToArray();

            DataSet ds = GetAllDataTableFromSearchButton(pSize, pIndex, updateTime, experience, title, locationJ, categoryJ, employmentTypeJ, qualificationJ, skillsJ);

            if (ds == null)
                str = "";
            else
                str = ds.GetXml();
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

        return str;
    }

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string getDataByExperienceCVCUpdate(string pageSize, string pageIndex, string updateTime, string experience, string jobTitle, string location, string category, string employmentType, string qualification, string skills)
    {
        string str = string.Empty;
        try
        {
            int pSize = 0;
            if (!string.IsNullOrEmpty(pageSize))
                pSize = Convert.ToInt32(pageSize);
            int pIndex = 0;
            if (!string.IsNullOrEmpty(pageIndex))
                pIndex = Convert.ToInt32(pageIndex);

            string[] title = jobTitle.Split('$');
            string[] locationJ = location.Split('$');
            string[] categoryJ = category.Split('$');
            string[] employmentTypeJ = employmentType.Split('$');
            string[] qualificationJ = qualification.Split('$');
            string[] skillsJ = skills.Split('$');

            qualificationJ = qualificationJ.TakeWhile(n => n.Length > 0).ToArray();
            employmentTypeJ = employmentTypeJ.TakeWhile(n => n.Length > 0).ToArray();
            categoryJ = categoryJ.TakeWhile(n => n.Length > 0).ToArray();
            locationJ = locationJ.TakeWhile(n => n.Length > 0).ToArray();
            title = title.TakeWhile(n => n.Length > 0).ToArray();
            skillsJ = skillsJ.TakeWhile(n => n.Length > 0).ToArray();

            DataSet ds = GetAllDataTableFromSearchButton(pSize, 0, updateTime, experience, title, locationJ, categoryJ, employmentTypeJ, qualificationJ, skillsJ);
            if (ds == null)
                str = "";
            else
                str = ds.GetXml();
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

        return str;
    }

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string getBySkill(string skill, string pageSize, string updateTime, string experience, string jobTitle, string location, string category, string employmentType, string qualification, string skills)
    {
        string str = string.Empty;
        try
        {
            int pSize = Convert.ToInt32(pageSize);

            string[] title = jobTitle.Split('$');
            string[] locationJ = location.Split('$');
            string[] categoryJ = category.Split('$');
            string[] employmentTypeJ = employmentType.Split('$');
            string[] qualificationJ = qualification.Split('$');
            string[] skillsJ = skills.Trim().Split('$');

            qualificationJ = qualificationJ.TakeWhile(n => n.Length > 0).ToArray();
            employmentTypeJ = employmentTypeJ.TakeWhile(n => n.Length > 0).ToArray();
            categoryJ = categoryJ.TakeWhile(n => n.Length > 0).ToArray();
            locationJ = locationJ.TakeWhile(n => n.Length > 0).ToArray();
            title = title.TakeWhile(n => n.Length > 0).ToArray();

            skillsJ = skillsJ.TakeWhile(n => n.Length > 0).ToArray();
            skillsJ[skillsJ.Length - 1] = skill;///last index gets incomplete text from textbox

            DataSet ds = GetAllDataTableFromSearchButton(pSize, 0, updateTime, experience, title, locationJ, categoryJ, employmentTypeJ, qualificationJ, skillsJ);
            if (ds == null)
                str = "";
            else
                str = ds.GetXml();
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

        return str;

    }

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string getByCity(string search, string pageSize, string updateTime, string experience, string jobTitle, string location, string category, string employmentType, string qualification, string skills)
    {
        string str = string.Empty;
        try
        {
            int pSize = Convert.ToInt32(pageSize);

            string[] title = jobTitle.Split('$');
            string[] locationJ = location.Split('$');
            string[] categoryJ = category.Split('$');
            string[] employmentTypeJ = employmentType.Split('$');
            string[] qualificationJ = qualification.Split('$');
            string[] skillsJ = skills.Trim().Split('$');

            qualificationJ = qualificationJ.TakeWhile(n => n.Length > 0).ToArray();
            employmentTypeJ = employmentTypeJ.TakeWhile(n => n.Length > 0).ToArray();
            categoryJ = categoryJ.TakeWhile(n => n.Length > 0).ToArray();
            locationJ = locationJ.TakeWhile(n => n.Length > 0).ToArray();
            skillsJ = skillsJ.TakeWhile(n => n.Length > 0).ToArray();
            title = title.TakeWhile(n => n.Length > 0).ToArray();

            locationJ[locationJ.Length - 1] = search;///last index gets incomplete text from textbox

            DataSet ds = GetAllDataTableFromSearchButton(pSize, 0, updateTime, experience, title, locationJ, categoryJ, employmentTypeJ, qualificationJ, skillsJ);
            if (ds == null)
                str = "";
            else
                str = ds.GetXml();

        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
        return str;

    }

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string getByCategory(string search, string pageSize, string updateTime, string experience, string jobTitle, string location, string category, string employmentType, string qualification, string skills)
    {
        string str = string.Empty;

        try
        {

            int pSize = 0;
            int.TryParse(pageSize, out pSize);

            string[] title = jobTitle.Split('$');
            string[] locationJ = location.Split('$');
            string[] categoryJ = category.Split('$');
            string[] employmentTypeJ = employmentType.Split('$');
            string[] qualificationJ = qualification.Split('$');
            string[] skillsJ = skills.Split('$');

            qualificationJ = qualificationJ.TakeWhile(n => n.Length > 0).ToArray();
            employmentTypeJ = employmentTypeJ.TakeWhile(n => n.Length > 0).ToArray();
            categoryJ = categoryJ.TakeWhile(n => n.Length > 0).ToArray();
            locationJ = locationJ.TakeWhile(n => n.Length > 0).ToArray();
            skillsJ = skillsJ.TakeWhile(n => n.Length > 0).ToArray();
            title = title.TakeWhile(n => n.Length > 0).ToArray();

            categoryJ[categoryJ.Length - 1] = search;///last index gets incomplete text from textbox            
            DataSet ds = GetAllDataTableFromSearchButton(pSize, 0, updateTime, experience, title, locationJ, categoryJ, employmentTypeJ, qualificationJ, skillsJ);
            if (ds == null)
                str = "";
            else
                str = ds.GetXml();
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
        return str;
    }

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string getByEmploymentType(string search, string pageSize, string updateTime, string experience, string jobTitle, string location, string category, string employmentType, string qualification, string skills)
    {
        string str = string.Empty;

        try
        {
            int pSize = Convert.ToInt32(pageSize);

            string[] title = jobTitle.Split('$');
            string[] locationJ = location.Split('$');
            string[] categoryJ = category.Split('$');
            string[] employmentTypeJ = employmentType.Split('$');
            string[] qualificationJ = qualification.Split('$');
            string[] skillsJ = skills.Trim().Split('$');

            qualificationJ = qualificationJ.TakeWhile(n => n.Length > 0).ToArray();
            employmentTypeJ = employmentTypeJ.TakeWhile(n => n.Length > 0).ToArray();
            categoryJ = categoryJ.TakeWhile(n => n.Length > 0).ToArray();
            locationJ = locationJ.TakeWhile(n => n.Length > 0).ToArray();
            skillsJ = skillsJ.TakeWhile(n => n.Length > 0).ToArray();
            title = title.TakeWhile(n => n.Length > 0).ToArray();

            employmentTypeJ[employmentTypeJ.Length - 1] = search;///last index gets incomplete text from textbox

            DataSet ds = GetAllDataTableFromSearchButton(pSize, 0, updateTime, experience, title, locationJ, categoryJ, employmentTypeJ, qualificationJ, skillsJ);
            if (ds == null)
                str = "";
            else
                str = ds.GetXml();
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
        return str;
    }

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string getByQualification(string search, string pageSize, string updateTime, string experience, string jobTitle, string location, string category, string employmentType, string qualification, string skills)
    {
        string str = string.Empty;

        try
        {
            int pSize = Convert.ToInt32(pageSize);

            string[] title = jobTitle.Split('$');
            string[] locationJ = location.Split('$');
            string[] categoryJ = category.Split('$');
            string[] employmentTypeJ = employmentType.Split('$');
            string[] qualificationJ = qualification.Split('$');
            string[] skillsJ = skills.Trim().Split('$');

            qualificationJ = qualificationJ.TakeWhile(n => n.Length > 0).ToArray();
            employmentTypeJ = employmentTypeJ.TakeWhile(n => n.Length > 0).ToArray();
            categoryJ = categoryJ.TakeWhile(n => n.Length > 0).ToArray();
            locationJ = locationJ.TakeWhile(n => n.Length > 0).ToArray();
            skillsJ = skillsJ.TakeWhile(n => n.Length > 0).ToArray();
            title = title.TakeWhile(n => n.Length > 0).ToArray();

            qualificationJ[qualificationJ.Length - 1] = search;///last index gets incomplete text from textbox

            DataSet ds = GetAllDataTableFromSearchButton(pSize, 0, updateTime, experience, title, locationJ, categoryJ, employmentTypeJ, qualificationJ, skillsJ);
            if (ds == null)
                str = "";
            else
                str = ds.GetXml();
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
        return str;
    }

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string getDataSearchAll(string pageSize, string pageIndex, string id, string updateTime, string experience, string jobTitle, string location, string category, string employmentType, string qualification, string skills)
    {
        string str = string.Empty;

        try
        {
            int pSize = 0;
            if (!string.IsNullOrEmpty(pageSize))
                pSize = Convert.ToInt32(pageSize);
            int pIndex = 0;
            if (!string.IsNullOrEmpty(pageIndex))
                pIndex = Convert.ToInt32(pageIndex);
            int ID = 0;

            if (!string.IsNullOrEmpty(id))
                int.TryParse(id, out ID);


            string[] title = jobTitle.Split('$');
            string[] locationJ = location.Split('$');
            string[] categoryJ = category.Split('$');
            string[] employmentTypeJ = employmentType.Split('$');
            string[] qualificationJ = qualification.Split('$');
            string[] skillsJ = skills.Split('$');

            qualificationJ = qualificationJ.TakeWhile(n => n.Length > 0).ToArray();
            employmentTypeJ = employmentTypeJ.TakeWhile(n => n.Length > 0).ToArray();
            categoryJ = categoryJ.TakeWhile(n => n.Length > 0).ToArray();
            locationJ = locationJ.TakeWhile(n => n.Length > 0).ToArray();
            title = title.TakeWhile(n => n.Length > 0).ToArray();
            skillsJ = skillsJ.TakeWhile(n => n.Length > 0).ToArray();

            DataSet ds = GetAllDataTableFromSearchButton(pSize, pIndex, updateTime, experience, title, locationJ, categoryJ, employmentTypeJ, qualificationJ, skillsJ);
            if (ds == null)
                str = "";
            else
                str = ds.GetXml();

        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
        return str;
    }

    #endregion

}